package edu.xlh.travel.dao;

import edu.xlh.travel.pojo.Carousel;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface CarouselDao extends JpaRepository<Carousel,String>, JpaSpecificationExecutor<Carousel> {
    @Modifying
    @Query(value = "update t_carousel set " +
            "title = CASE WHEN :#{#carousel.title} IS NULL THEN title ELSE :#{#carousel.title} END," +
            "comment = CASE WHEN :#{#carousel.comment} IS NULL THEN comment ELSE :#{#carousel.comment}  END," +
            "modify_time= CASE WHEN  :#{#carousel.modifyTime} IS NULL THEN modify_time ELSE :#{#carousel.modifyTime} END " +
            "where id =:#{#carousel.id}",nativeQuery = true )
    void updateCarouselByCarouselId(@Param("carousel") Carousel carousel);

    @Transactional
    @Modifying
    @Query(value = "update Carousel set delFlag =?2 where id =?1")
    void updateCarouselDelFlagByCarouselId(String carouselId, String delFlag);
}
